package aqua.smile.springboot.srvapi.config;

import aqua.smile.springboot.srvapi.controller.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@ConditionalOnProperty(name = "node.type", havingValue = "master")
@Configuration
public class TestConfig implements InitializingBean {

    @Autowired
    private static Result okRes;
    @Autowired
    private ApplicationContext applicationContext;

    @Configuration
    class A {

        @Bean
        public Result okRes() {
            log.info("okRes1: {} ", okRes);
            log.info("okRes............");
            return new Result().setMsg("xixixi");
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("okRes2: {} ", okRes);
        log.info("okRes2: {} ", applicationContext.getBean(Result.class));
    }
}
